package yicheng.dinnertogetherapp;

import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;
import yicheng.dinnertogetherapp.R;

public class UserMainTabViewActivity extends TabActivity {



	SharedPreferences local_user_information;
	SharedPreferences.Editor local_user_editor;
	String PREFS_NAME = "LocalUserInfo";

	public static AmazonClientManager clientManager;

	TabHost tabHost;

	Handler handler;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

		overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
		clientManager = new AmazonClientManager();

		setContentView(R.layout.user_main_activity_tabview);

		setUpTabLayout();








	}


	private void setUpTabLayout(){
		tabHost = getTabHost();

		Intent friendListTabIntent = new Intent(this, FriendListActivity.class);
		TabSpec friendListTabSpec = tabHost.newTabSpec("FriendList")
				.setIndicator(null, getResources().getDrawable(R.drawable.ic_action_cc_bcc))
				.setContent(friendListTabIntent);
		tabHost.addTab(friendListTabSpec);

		Intent friendManagerTabIntent = new Intent(this, FriendManagerActivity.class);
		TabSpec friendManagerTabSpec = tabHost.newTabSpec("FriendManager")
				.setIndicator(null, getResources().getDrawable(R.drawable.ic_action_search))
				.setContent(friendManagerTabIntent);
		tabHost.addTab(friendManagerTabSpec);

		Intent myInfoTabIntent = new Intent(this, MyInfoActivity.class);
		TabSpec myInfoTabSpec = tabHost.newTabSpec("MyInfo")
				.setIndicator(null, getResources().getDrawable(R.drawable.ic_action_person))
				.setContent(myInfoTabIntent);
		tabHost.addTab(myInfoTabSpec);

		tabHost.setCurrentTab(2);
		
		tabHost.getTabWidget().getChildAt(0).setBackgroundColor(Color.rgb(255, 255, 255));
		tabHost.getTabWidget().getChildAt(1).setBackgroundColor(Color.rgb(255, 255, 255));
		tabHost.getTabWidget().getChildAt(2).setBackgroundColor(Color.rgb(255, 255, 255));
		
		tabHost.getTabWidget().getChildAt(0).setAlpha((float) 0.4);
		tabHost.getTabWidget().getChildAt(1).setAlpha((float) 0.4);
		tabHost.getTabWidget().getChildAt(2).setAlpha((float) 1);

		
		
		
		tabHost.setOnTabChangedListener(new OnTabChangeListener(){

			@Override
			public void onTabChanged(String tabId) {
				// TODO Auto-generated method stub
				if (tabId.equals("FriendList")){
					tabHost.getTabWidget().getChildAt(0).setAlpha((float) 1);
					tabHost.getTabWidget().getChildAt(1).setAlpha((float) 0.4);
					tabHost.getTabWidget().getChildAt(2).setAlpha((float) 0.4);
				}
				else if(tabId.equals("FriendManager")){
					tabHost.getTabWidget().getChildAt(0).setAlpha((float) 0.4);
					tabHost.getTabWidget().getChildAt(1).setAlpha((float) 1);
					tabHost.getTabWidget().getChildAt(2).setAlpha((float) 0.4);
				}
				else{
					tabHost.getTabWidget().getChildAt(0).setAlpha((float) 0.4);
					tabHost.getTabWidget().getChildAt(1).setAlpha((float) 0.4);
					tabHost.getTabWidget().getChildAt(2).setAlpha((float) 1);
				}
			}
			
		});
	
	}


	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		moveTaskToBack(true);
	}



	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		if (keyCode == KeyEvent.KEYCODE_BACK ) {
			//preventing default implementation previous to 
			//android.os.Build.VERSION_CODES.ECLAIR
			moveTaskToBack(true);

			return false;
		}     
		return super.onKeyDown(keyCode, event);    

	}



	/*private class loadDataBase extends AsyncTask<Void, Void, Void> {

		@Override
		protected Void doInBackground(Void... Void) {
			// TODO Auto-generated method stu
			loadingSpinner.setVisibility(View.VISIBLE);
			domainNames = SimpleDB.getDomainNames(clientManager);


			//loadingSpinner.setVisibility(View.VISIBLE);


				}
			catch (NullPointerException e){
				Toast.makeText(getApplicationContext(), "Your connection to Internet has problem, please check.", Toast.LENGTH_SHORT).show();
			}
			Message msg = Message.obtain();
			msg.what = 1;
			handler.sendMessage(msg);
			//return null;
			return null;
		}
	}*/


}
